package name.marz.to.go.ahg.mhbk.executer;

import java.io.IOException;
import java.net.URI;

import name.marz.to.go.ahg.common.util.HttpUtil;
import name.marz.to.go.ahg.core.AutoGetterHttpClient;
import name.marz.to.go.ahg.core.exception.OutOfServiceException;
import name.marz.to.go.ahg.core.executer.DocumentGetExecuter;

import org.apache.http.client.ClientProtocolException;
import org.jsoup.nodes.Document;

public class MHBKTopPageExecuter extends DocumentGetExecuter {
//	private static final Logger log = Logger.getLogger(MHBKTopPageExecuter.class.getName());

	/**
	 * @param client
	 * @deprecated
	 */
	public MHBKTopPageExecuter(AutoGetterHttpClient client) {
		super(HttpUtil.createURISafety("https://web.ib.mizuhobank.co.jp/servlet/mib?xtr=Emf00000"), client);
	}

	public MHBKTopPageExecuter(URI uri, AutoGetterHttpClient client) {
		super(uri, client,"TOP");
	}

	@Override
	public Document execute() throws ClientProtocolException, IOException {
		Document doc = super.execute();
		// サービス時間外か判定
		final String OUTOFSERV＿CHK_STR="現在このサービスはご利用いただけません。";
		if ( doc.html().contains(OUTOFSERV＿CHK_STR) )
			throw new OutOfServiceException();
		
		URI next_uri= HttpUtil.createURISafety("https://web.ib.mizuhobank.co.jp/servlet/LOGBNK0000000B.do");
		DocumentGetExecuter e2 = new DocumentGetExecuter(next_uri, client,"top-redirect");
		doc = e2.execute();
		return doc;
	}

}
